/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.crowtheries.wirelessrouting.messages;

import ptolemy.data.IntToken;
import ptolemy.data.RecordToken;
import ptolemy.data.StringToken;
import ptolemy.data.Token;
import ptolemy.kernel.util.IllegalActionException;

/**
 *
 * @author knuthy
 */
public class RREQ{
    private RecordToken rreqToken;

    public RREQ(String SRCIP, int SRCSEQ, String DSTIP, int DSTSEQ, int RREQID) throws IllegalActionException{
        rreqToken=new RecordToken(new String[]{
            "SRCIP",
            "SRCSEQ",
            "DSTIP",
            "DSTSEQ",
            "RREQID",
            "HOPCOUNT"
        },new Token[]{
            new StringToken(SRCIP),
            new IntToken(SRCSEQ),
            new StringToken(DSTIP),
            new IntToken(DSTSEQ),
            new IntToken(RREQID),
            new IntToken(0)
        });
    }

    public RREQ(RecordToken rreq){
        this.rreqToken=rreq;
    }

    /**
     * Increments the HOPCOUNT value
     * @throws ptolemy.kernel.util.IllegalActionException
     */
    public void incHop() throws IllegalActionException{
        IntToken hopCount= (IntToken) rreqToken.get("HOPCOUNT");
        rreqToken.merge(rreqToken, new RecordToken(new String[]{"HOPCOUNT"},
                new Token[]{new IntToken(hopCount.intValue()+1)}));
    }

    public RecordToken getRequestToken(){
        return rreqToken;
    }
}
